package com.sunrise.xdoc.entity.operator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.validator.constraints.Email;

import com.sunrise.xdoc.entity.AbstractAuditEntity;
import com.sunrise.xdoc.entity.config.ChiNhanh;
import com.sunrise.xdoc.entity.user.User;

@Entity
@Table(name = "op_operator")
@Inheritance(strategy = InheritanceType.JOINED)
public class Operator extends AbstractAuditEntity {
	private static final long serialVersionUID = 8102323664852029996L;
	private User user;
	private ChiNhanh chiNhanh;
	private OperatorState state = OperatorState.INACTIVE;
	private String email;

	// Chua vao lam, Dang hoat dong, ngung hoat dong trong app, da nghi cong ty
	public enum OperatorState {
		PREPARING, ACTIVE, INACTIVE, OUT
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@Cascade(value = { CascadeType.ALL })
	@JoinColumn(name = "user_id")
	@NotNull
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "chi_nhanh_id")
	public ChiNhanh getChiNhanh() {
		return chiNhanh;
	}

	public void setChiNhanh(ChiNhanh chiNhanh) {
		this.chiNhanh = chiNhanh;
	}

	@Enumerated(EnumType.STRING)
	@Column(name = "state")
	public OperatorState getState() {
		return state;
	}

	public void setState(OperatorState state) {
		this.state = state;
	}

	@Column(name = "email")
	@Email(message = "Email chưa đúng định dạng")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
}
